<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<head>
</head>
<body>
<article class="page-container" id="mainArt">
	<form:form  id="form1" modelAttribute="entity" class="form form-horizontal" action="${ctx}/code/saveEntity.do" method="post" enctype="multipart/form-data">
		<c:if test="${entity.id != null}"><input type="hidden" id="entityID" name="id" value="${entity.id }" /></c:if>
		<div class="row cl">
			<label class="form-label col-xs-2"><span class="c-red">*</span>类型:</label>
			<div class="formControls col-xs-10">
				<form:select path="type"  class="required" style="width:100%" items="${fns:getDictList('sys_code')}" itemLabel="label" itemValue="value"  htmlEscape="false"></form:select>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-2"><span class="c-red">*</span>名称:</label>
			<div class="formControls col-xs-10">
				<input id="codeName" name="codeName" class="input-text required" value="${entity.codeName}"  type="text"/>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-2"><span class="c-red">*</span>值:</label>
			<div class="formControls col-xs-10">
				 <input id="codeValue" name="codeValue" class="input-text required" value="${entity.codeValue }"  type="text"/>
				<div id="fileSpan" style="display: none;">
					<span class="btn-upload form-group">
					  <input name="uploadfile-2" id="uploadfile-2" value="${entity.codeValue }" class="input-text upload-url radius" placeholder="建议:750*336" type="text"  readonly>
					  <a href="javascript:void(0);" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
					  <input type="file"  name="file" class="input-file" accept="image/*">
					</span>
					<c:if test="${!empty entity.codeValue }">
						<div>
							<img src="${entity.codeValue }" width="20%" />
						</div>
					</c:if>
				</div>
			</div>
		</div>	
		<div class="row cl">
			<label class="form-label col-xs-2">备注:</label>
			<div class="formControls col-xs-10">
				<textarea id="remarks" name="remarks" class="input-text" 
					 type="text" style="width: 100%; height: 100px;">${entity.remarks } </textarea>
			</div>
		</div>
	
		<div class="row cl">
			<div id="buttonDiv" class="col-xs-6 col-xs-offset-3 text-c">
				<c:if test="${entity.id != null}">
					<a href="javascript:submit();" class="btn btn-success radius"><i class="Hui-iconfont">&#xe60c;</i> 修改</a>
				</c:if>
				<c:if test="${entity.id == null}">
					<a href="javascript:submit();" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加</a>
				</c:if>
			</div>
		</div>
	</form:form>
</article>
<script type="text/javascript">
var eid = "${entity.id}";
var isOnly = "${entity.isOnly}";
var isDel = "${entity.isDel}";
var codeNameV = "${entity.codeName}";
var codeValue = "${entity.codeValue }";
var type = "${entity.type}";
$("#type").select2();
//如果是不能删除只能修改的数据
if((stringNotNull(isOnly) && isOnly == 1)||(stringNotNull(isDel) && isDel == 0)){
    $("#codeName").attr("disabled","disabled");
	$("#type").prop("disabled", true);
	$("#remarks").prop("disabled", true);
	$("#codeValue").attr("class","input-text required ");/*digits*/
	$("#codeValue").parent().attr("class","formControls col-xs-2");
	if(getDictValue(${fns:getDictListJson('sys_code')},'水印', '')==type){
		 $("#codeValue").parent().attr("class","formControls col-xs-10");
		 $("#fileSpan").show();
		 $("#codeValue").remove();
	}else if(getDictValue(${fns:getDictListJson('sys_code')},'平台抽成', '')==type){
		$("#codeValue").parent().after("<label class='form-label col-xs-2'>%</label>");
	}else if(getDictValue(${fns:getDictListJson('sys_code')},'会员', '')==type){
		$("#codeValue").parent().after("<label class='form-label col-xs-2'>%</label>");
	}else if(getDictValue(${fns:getDictListJson('sys_code')},'视频直播开关', '')==type){
		var text = "<select id='codeValue' name='codeValue'>"+
					"<option value='1'>开</option>"+
					"<option value='0'>关</option>"+
				"</select>"
		 $("#codeValue").after(text);
		 $("#codeValue").parent().find("input").remove();
		 $("#codeValue").val(codeValue).trigger("change");
	}else {
        $("#codeValue").parent().attr("class","formControls col-xs-10");
	    /*else if(codeNameV>8 && codeNameV<20){
		 $("#codeValue").parent().attr("class","formControls col-xs-10");
		 var text = "<textarea id='codeValue' name='codeValue' class='input-text'"+
		 "type='text' style='width: 382px; height: 100px;'>"+codeValue+" </textarea>";
		 $("#codeValue").after(text);
		 $("#codeValue").parent().find("input").remove();
		 }else{
		 $("#codeValue").parent().after("<label class='form-label col-xs-2'>分钟</label>");
		 }*/
    }
    if(codeNameV=="年费会员价格"){
        $("#codeValue").attr("class","input-text required digits");
    }
}



	$(function(){
		$("#form1").validate({
			onkeyup:false,
			focusCleanup:true,
			success:"valid",
			submitHandler:function(form){
				var index = layer.load();
				$(form).ajaxSubmit({
	                success:function(data){ //提交成功的回调函数  
	            	  	layer.close(index);  
	                    if(data.flag==200){
	    		        	layer.alert(data.msg,{icon:6},function(index){
	                			if(data.isUpdate == "false"){
	                				parent.location.reload();
	                			}else{
	                				parent.reloadTable();
	                			}
    		                	//关闭当前弹窗
    		    				var index = parent.layer.getFrameIndex(window.name);
    		    				parent.$('.btn-refresh').click();
    		    				parent.layer.close(index);
                				layer.close(index);
                			});
	    	       		} else{
	    	       			layer.alert(data.msg, {icon: 5});
	    	       		}
	                },
	                error:function(data){
	            		layer.close(index);  
	                	layer.alert("操作失败",{icon:5},function(index){
            				//刷新父级
            				parent.location.reload();
		                	//关闭当前弹窗
		    				var index = parent.layer.getFrameIndex(window.name);
		    				parent.$('.btn-refresh').click();
		    				parent.layer.close(index);
            				layer.close(index);
            			});     
	                }
				});
			}
		});
	});
	function submit(){
		$("#form1").submit();
	}
</script>
</body>
